<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\MessageBag;

class Department extends Model
{
    protected $table = 'love_department';

    const UPDATED_AT = null;

    public function scopeAll()
    {
        return $this->where('status', 1);
    }

    public function users()
    {
        return $this->hasMany(\App\Models\Department\User::Class);
    }

    /*public static function boot()
    {
        parent::boot();

        static::deleted(function ($model)
        {
            $user_count = Department\User::where('department_id', $model->id)->count();
            if ($user_count) {
                $error = new MessageBag([
                    'title'   => '删除失败',
                    'message' => '该部门下有成员存在,不能直接删除',
                ]);

                return back()->with(compact('error'));
            }

        });

    }*/




}
